import axios from 'axios';

export default {
  async get() {
    // throw new Error("API demo error")
    // eslint-disable-next-line no-unreachable
    let data = (await axios.get("https://api.dreamhub.moyunbook.xyz/user/current/")).data.user
    return {
      account: {
        avatarImg: data.profile.avatar,
        username: data.username,
        bio: data.profile.intro,
        email: data.profile.email
      },
      information: {
        bio: 'The name’s John Deo. I am a tireless seeker of knowledge, occasional purveyor of wisdom and also, coincidentally, a graphic designer. Algolia helps businesses across industries quickly create relevant 😎, scaLabel 😀, and lightning 😍 fast search and discovery experiences.',
        phone: '954-006-0844',
        website: 'https://themeselection.com/',
        address: 'some address bla bla',
        gender: 'male',
      },
      raw: data
    }
  },
  async upload_avatar(user, avatar) {
    var form = new FormData();
    form.append("avatar", avatar)
    return await axios.patch(`https://api.dreamhub.moyunbook.xyz/user/${user}/profile/`, form)
  },
  async change_settings(user, bio, email) {
    var form = {intro: bio, email: email}
    return await axios.patch(`https://api.dreamhub.moyunbook.xyz/user/${user}/profile/`, form)
  },
  async change_password(pold, pnew) {
    return await axios.patch("https://api.dreamhub.moyunbook.xyz/user/password/", {old_password: pold, new_password: pnew})
  }
}
